package com.wangyi.im.remoting;

import com.alibaba.fastjson.JSONObject;
import com.wangyi.im.execute.IMUserExecute;
import com.wangyi.im.request.IMUserRequest;
import com.wangyi.im.request.IMUsersRequest;
import com.wangyi.im.response.IMResponse;
import com.wangyi.im.response.IMUserResponse;
import com.wangyi.im.utils.BuildDataUtil;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.List;

import static com.wangyi.im.constants.CommonConstants.*;

public class IMUserRemoting extends Remoting {

    public IMUserRemoting(String baseUrl, String appKey, String appSecret) {
        super(baseUrl, appKey, appSecret);
    }

    public IMResponse<IMUserResponse> updateUserInfo(IMUserRequest imUserRequest){
        Call<JSONObject> call = getRetrofit(imUserRequest).create(IMUserExecute.class).updateUserInfo();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildData(retrofitResponse, IMUserResponse.class, null);
    }

    public IMResponse<List<IMUserResponse>> getUserInfos(IMUsersRequest imUsersRequest){
        Call<JSONObject> call = getRetrofit(imUsersRequest).create(IMUserExecute.class).getUserInfos();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildListData(retrofitResponse, IMUserResponse.class, UINFOS);
    }

    public IMResponse<IMUserResponse> setDonnop(IMUserRequest imUserRequest){
        Call<JSONObject> call = getRetrofit(imUserRequest).create(IMUserExecute.class).setDonnop();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildData(retrofitResponse, IMUserResponse.class, UINFOS);
    }

    public IMResponse<IMUserResponse> mute(IMUserRequest imUserRequest){
        Call<JSONObject> call = getRetrofit(imUserRequest).create(IMUserExecute.class).mute();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildData(retrofitResponse, IMUserResponse.class, null);
    }

    public IMResponse<IMUserResponse> muteAv(IMUserRequest imUserRequest){
        Call<JSONObject> call = getRetrofit(imUserRequest).create(IMUserExecute.class).muteAv();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildData(retrofitResponse, IMUserResponse.class, null);
    }
}
